927. Number of toys

 

You are given the number of types of toys in the shop, along with the quantity and cost of each type. Find the total number of toys that cost less than 50 grn.

 

Input. The first line contains the number of types of toys n (0 ≤ n ≤ 1000). Each of the next n lines contains two numbers: the count of toys a (0 ≤ a ≤ 1000) of the next type and the price b (0 < b ≤ 10000) of each toy in grn.

 

Output. Print the total number of toys that cost less than 50 grn.

 

Sample input

Sample output

3

2 100.00

5 23.00

10 22.50

15

 

 

SOLUTION

loops

 

Algorithm analysis

For each type of toy, read its quantity and price. If the price is less than 50 grn, add the number of such toys to the total count.

 

Algorithm realization

Read the number of toy types n.

 

scanf("%d",&n);

 

Use the variable res to store the total count of toys with a price less than 50 grn.

 

res = 0;

 

Read and process the information about toys.

 

for(i = 0; i < n; i++)

{

  scanf("%d %lf",&num,&price);

  if (price < 50.0) res += num;

}

 

Print the answer.

 

printf("%d\n",res);

 

Java realization

 

import java.util.*;

 

public class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    //con.useLocale(new Locale("US"));

    //con.useLocale(Locale.US);

    int res = 0;

    int n = con.nextInt();

    for (int i = 0; i < n; i++)

    {

      int num = con.nextInt();       

      double price = con.nextDouble();

      if (price < 50.0) res += num;

    }

    System.out.println(res);

    con.close();

  }

}

 

Python realization

Read the number of toy types n.

 

n = int(input())

 

Use the variable res to store the total count of toys with a price less than 50 grn.

 

res = 0

 

Read and process the information about toys.

 

for _ in range(n):

  num, price = input().split()

  num = int(num)

  price = float(price)

  if price < 50.0: res += num

 

Print the answer.

 

print(res)